package org.darcy.service.check.impl;

import java.util.List;

import org.darcy.dao.CheckItemMapper;
import org.darcy.entity.CheckItem;
import org.darcy.framework.generic.GenericServiceImpl;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.service.check.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.hutool.core.util.StrUtil;

/**
 * CheckItem服务实现
 */
@Service
@Transactional
public class CheckItemServiceImpl extends GenericServiceImpl<CheckItem> implements CheckItemService {

	@Autowired
	private CheckItemMapper mapper;

	@Override
	public CheckItem getDetail(Integer id) {
		CheckItem record = mapper.selectById(id);
		return record;
	}

	@Override
	public PageData<CheckItem> page(PageParam<CheckItem> param) {
		CheckItem p = param.getEntity();
		QueryWrapper<CheckItem> wrapper = new QueryWrapper<CheckItem>();
		if (StrUtil.isNotEmpty(p.getCheckType())) {
			wrapper.eq("check_type", p.getCheckType());
		}
		if (StrUtil.isNotEmpty(p.getCheckItem())) {
			wrapper.like("check_item", p.getCheckItem());
		}
		IPage page = new Page(param.getQuery().getPageNum(), param.getQuery().getPageSize());
		IPage list = this.getPage(page, wrapper);
		PageData data = new PageData(list, param);
		return data;
	}

	@Override
	public List<CheckItem> getList(String type) {
		QueryWrapper<CheckItem> q = new QueryWrapper<CheckItem>();
		q.eq("check_type", type);
		return this.getList(q);
	}

}
